package pers.emok.springcloud.serviceprovider.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import pers.emok.springcloud.serviceprovider.config.DemoProperties;
import pers.emok.springcloud.serviceprovider.config.TestProperties;

import javax.annotation.Resource;

@RestController
@RefreshScope
public class ApiController {

    @Value("${useLocalCache:false}")
    private boolean useLocalCache;

    @Value("${demo.title:false}")
    private String demoTitle;

    private final DemoProperties demoProperties;
    @Autowired
    private TestProperties testProperties;

    public ApiController(DemoProperties demoProperties) {
        this.demoProperties = demoProperties;
    }

    @GetMapping("/echo/{data}")
    public String echo(@PathVariable String data){
        return "provider/"+data;
    }

    @GetMapping("/config")
    public String config(){
        return "provider/config/"+useLocalCache;
    }

//    @GetMapping("/config/demo")
//    public String configDemo(){
//        if (demoProperties == null) {
//            System.out.println("demoConfig == null .");
//        }
//        return "provider/config/demo/"+ demoTitle + "/"+ demoProperties;
//    }

//    @GetMapping("/config/test1")
//    public String configtest1(){
//        return "provider/config/test1/"+ TestProperties.name ;
//    }

    @GetMapping("/config/test")
    public String configtest(){
        return "provider/config/test/"+ testProperties.getName() ;
    }
}
